package com.example.jobback.controller.manager;

import com.example.jobback.req.common.password.ResetPasswordReq;
import com.example.jobback.req.common.phone.ResetPhoneReq;
import com.example.jobback.result.Result;
import com.example.jobback.service.manager.ManagerAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: ManagerAuthController
 * @Description:管理员-身份核验控制器
 * @Author: lhb
 * @Date: 2025/6/21
 */
@RestController
@RequestMapping("/manager/auth")
@Tag(name = "管理员-身份核验控制器",description = "管理员身份核验服务的相关接口")
public class ManagerAuthController {

    private final ManagerAuthService managerAuthService;

    public ManagerAuthController(ManagerAuthService managerAuthService) {
        this.managerAuthService = managerAuthService;
    }

//    @Operation(summary = "登录", description = "手机号登录")
//    @PostMapping("/loginByPhone")
//    @ApiResponse(description = "返回token，前端设置token")
//    public Result<Object> loginByPhone(
//            @Parameter(description = "电话号码", required = true)
//            @Pattern(regexp = "^\\d{11}$", message = "电话号码必须是11位数字")
//            @RequestParam String phone,
//            @Parameter(description = "验证码", required = true)
//            @Pattern(regexp = "^\\d{4}$", message = "验证码必须是4位数字")
//            @RequestParam String code){
//        return managerAuthService.LoginByPhone(phone,code);
//    }


    @Operation(summary = "退出登录",description = "无")
    @PostMapping("/loginOut")
    public Result<Object> loginOut(){
        return managerAuthService.LoginOut();
    }



    @Operation(summary = "新管理员登录", description = "手机号登录")
    @PostMapping("/login")
    @ApiResponse(description = "返回token，前端设置token")
    public Result<Object> login(
            @Parameter(description = "电话号码", required = true)
            @Pattern(regexp = "^\\d{11}$", message = "电话号码必须是11位数字")
            @RequestParam String phone,
            @Parameter(description = "密码", required = true)
            @RequestParam String password){
        return managerAuthService.login(phone,password);
    }

    @Operation(summary = "修改密码",description = "需要传递旧密码，建议修改后执行登出逻辑，重新登录")
    @PostMapping("/resetPassword")
    @ApiResponse(description = "")
    public Result<Object> resetPassword(@Validated
                                        @RequestBody
                                        ResetPasswordReq resetPasswordReq){
        return managerAuthService.resetPassword(resetPasswordReq);
    }

    @Operation(summary = "更换手机号",description = "需要传递旧密码，建议修改后执行登出逻辑，重新登录")
    @PostMapping("/resetPhone")
    @ApiResponse(description = "")
    public Result<Object> resetPhone(@Validated
                                        @RequestBody
                                     ResetPhoneReq resetPhoneReq){
        return managerAuthService.resetPhone(resetPhoneReq);
    }
}
